// const BASE_URL = 'http://localhost:8081';
//测试地址
// const BASE_URL = 'https://api.t.guzift.com';
//生产地址
const BASE_URL = 'https://api.guzift.com';
const LOGIN_PATH = '/pages/login/auth';

export const sendRequest = (options) => {
    const accessToken = uni.getStorageSync('access-token');
    uni.showLoading({title: '加载中...'});
    uni.request({
        url: BASE_URL + options.url,
        method: options.method ,
        header: {'access-token': accessToken},
        data: options.data || {},
        success: (res) => {
            if (res.data.code === '70001') {
                uni.navigateTo({
                    url: LOGIN_PATH
                });
                closeLoading();
            }
            if (res.data.code === '20000') {
                options.success(res.data);
                closeLoading();
            } else {
                uni.showToast({
                    title: res.data.message,
                    icon: 'none'
                });

            }
        },
        fail: (err) => {
            uni.showToast({
                title: "服务器异常",
                icon: 'none'
            });
            closeLoading();
            reject(err)
        }
    })
};
function closeLoading() {
    setTimeout(function () {uni.hideLoading();}, 100);
}

// 查询字典数据详细
export function getDictList(dictType, options) {

    sendRequest({
        url: '/api/wx/getDictData',
        method: 'post',
        data: {'dictType': dictType},
        success: (cts) => {
            options.success(cts);
        }
    });

}

// 回显数据字典
export function selectDictLabel(datas, value) {
    let actions = [];
    Object.keys(datas).map((key) => {
        if (datas[key].dictValue === ('' + value)) {
            actions.push(datas[key].dictLabel);
            return false;
        }
    });
    return actions.join('');
}

export default BASE_URL;
